﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace qf_cms.admin
{
	public partial class columnGeneral : SessionPage
	{
		LogicLayer mgr = new LogicLayer();
		protected CMS_Columns curCol;

		protected string id = "";

		protected void Page_Load(object sender, EventArgs e)
		{
			id = Request.QueryString["id"] + "";

			if (!string.IsNullOrEmpty(Request.QueryString["delcid"]))
			{
				if (mgr.DisableColumns(Request.QueryString["delcid"]))
					Response.Redirect("columnGeneral.aspx?id=" + id );
			}

			if (!string.IsNullOrEmpty(Request.QueryString["delaid"]))
			{
				if (mgr.DisableArticle(Request.QueryString["delaid"]))
					Response.Redirect("columnGeneral.aspx?id=" + id);
			}

			if (!string.IsNullOrEmpty(id))
				curCol = mgr.GetCMS_Columns(id);
			if (curCol == null)
				curCol = new CMS_Columns();

			if (IsPostBack)
			{
				if (!string.IsNullOrEmpty(id))
				{ 
					
				}
			}
		}

		protected void WriteTableData()
		{ 
			List<CMS_Columns> colList =	mgr.ListColumns(id);
			if(colList == null)
				return;

			foreach(CMS_Columns col in colList)
            {
                Response.Write("<tr>");

                Response.Write("<td nowrap>");
				Response.Write(col.ColumnName);
                Response.Write("</td>");

				Response.Write("<td width=\"1%\" nowrap >");
				Response.Write("<a href=\"javascript:eidtCol('" + col.ColumnID + "')\">编辑</a>&nbsp;");
				Response.Write("<a href=\"javascript:delCol('" + col.ColumnID + "')\">删除</a>");
				Response.Write("</td>");

                Response.Write("</tr>");
            }
        }

		protected void WriteArticleData()
		{
			/*<th>标题</th>
			<th>内容</th>
			<th>发布时间</th>
			<th>类型</th>
			<th>栏目首页</th>
			<th>模板</th>*/

			List<CMS_Article> artList = mgr.ListCMS_Article(id);
			if (artList == null)
				return;

			foreach (CMS_Article art in artList)
			{
				Response.Write("<tr>");

				Response.Write("<td>");
				Response.Write("<a href=\"javascript:eidtArt('" + art.ArticleID + "')\">" + art.ArticleTitle + "</a>");
				Response.Write("</td>");
				//Response.Write("<td>");
				//Response.Write(art.ArticleContent);
				//Response.Write("</td>");
				Response.Write("<td>");
				Response.Write(art.CreateTime.ToString("yyyy-MM-dd"));
				Response.Write("</td>");
				Response.Write("<td>");
				Response.Write(art.ArticleType);
				Response.Write("</td>");
				Response.Write("<td>");
				Response.Write(art.TemplateID);
				Response.Write("</td>");
				Response.Write("<td>");
				if(art.IsDefault == 1)
					Response.Write("√");
				Response.Write("</td>");

				Response.Write("<td width=\"1%\" nowrap >");
				Response.Write("<a href=\"javascript:delArt('" + art.ArticleID + "')\">删除</a>");
				Response.Write("</td>");

				Response.Write("</tr>");
			}
		}
	}
}